﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Common;
using System.Data;
using System.IO;
using System.Net;
using System.Text;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    DBDataContext db;
    protected void Page_Load(object sender, EventArgs e)
    {
       // string myIp = Request.UserHostAddress;
        //Label1.Text = myIp;
        

        //Load Banner
        LoadSlide();
        //End Load Banner
    }
    private void LoadSlide()
    {
        db = new DBDataContext();
        var listbanner = (from a in db.Banners
                     where a.Status == 'A'
                     orderby a.SortOrder descending
                     select new
                     {
                         BannerID = a.ID,
                         ImagePath = a.ImagePath
                     }).ToList();
        StringBuilder sb = new StringBuilder();
        /*
        foreach (DataRow dr in dataTable.Rows)
        {
            string link = "javascript:;";
            //if (c.LinkTo.Trim().Length != 0)
            //{
            //    link = c.LinkTo;
            //}
            sb.Append("<a href='" + link + "'>");
            sb.Append("<img src='" + dr["ImagePath"] + "' alt='' Width='732px' Height='245px' />");
            sb.Append("</a>");
        }*/
        foreach (var p in listbanner)
        {
            //string link = "javascript:;";
            //if (c.LinkTo.Trim().Length != 0)
            //{
            //    link = c.LinkTo;
            //}
            sb.Append("<a href='#'>");
            sb.Append("<img class='noborder' src='" + Utils.getUrlImage() + p.ImagePath + "' alt='' Width='732px' Height='245px' />");
            sb.Append("</a>");
        }
        //sb.Append("<a href='#'>");
        //sb.Append("<img class='noborder' src='/Upload/Banner/bannerImg.png'  alt='' Width='732px' Height='245px' />");
        //sb.Append("</a>");
        //sb.Append("<a href='#'>");
        //sb.Append("<img class='noborder' src='/Upload/Banner/banner3.png' alt='' Width='732px' Height='245px' />");
        //sb.Append("</a>");
        //sb.Append("<a href='#'>");
        //sb.Append("<img class='noborder' src='/Upload/Banner/banner2.png' alt='' Width='732px' Height='245px' />");
        //sb.Append("</a>");
        ltrSlides.Text = sb.ToString();
    }


    
    protected void lbtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            string strParam = Utils.RemoveUnicode(txtProductNameSearch.Text.Trim()) + "@@@";
            // luu noi dung searh xuong Cookie
            HttpCookie param = new HttpCookie("ParamSearch");
            param.Value = strParam;
            param.Expires = DateTime.Now.AddMinutes(3);
            Response.Cookies.Add(param);
            Response.Redirect("~/tim-kiem-san-pham");
        }
        catch (Exception ex)
        {
            ControlUtil.LogError("Site Page-lbtnSearch_Click:" + ex.Message);
        }
    }
}
